package org.vergil.messagelistener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.vergil.websocket.TestWebSocketHandle;

import java.io.Serializable;
import java.util.Map;

public class DefaultMessageDelegate implements MessageDelegate {
    private static Logger log = LoggerFactory.getLogger(DefaultMessageDelegate.class);

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    RedisSerializer serializer;

    @Override
    public void handleMessage(String message) {
        log.info("--------handleMessage 1-----------");
        log.info(message);
    }

    @Override
    public void handleMessage(Map message) {
        log.info("--------handleMessage 2-----------");
    }

    @Override
    public void handleMessage(byte[] message) {
        log.info("--------handleMessage 3-----------");
        log.info(new String(message));
    }

    @Override
    public void handleMessage(Serializable message) {
        log.info("--------handleMessage 4-----------");
        log.info(message.toString());
    }

    @Override
    public void handleMessage(Serializable message, String channel) {
        log.info("--------handleMessage 5-----------");
        serializer = redisTemplate.getValueSerializer();
        log.info(message.toString() + "------>" + channel);
        TestWebSocketHandle.sendMessageToUsers(message.toString());
    }
}
